<?php
session_start();
require('../conn.php');
require('../functions.php');
require('admin.php');
//print_r($config);
//删除广告
if(is_numeric($_GET['del_id'])){
	$del_id=guolv($_GET['del_id']);
	$mysql->query("delete from `kaddata` where `id`='{$del_id}'");	
	echo "<script>alert('删除成功');location.href='kadlist.php'</script>";
	exit;		
}
//发布广告
if($_POST){
	$kad_title=guolv($_POST['kad_title']);
	$kad_logo=guolv($_POST['kad_logo']);
	$kad_profile=guolv($_POST['kad_profile']);
	$kad_url=guolv($_POST['kad_url']);

	if($ad_type!=='' && $ad_profile!=='' && $ad_endtime!==''&& $ad_title!==''&& $ad_thumb!==''&& $ad_url!==''){
		// if($ad_pv!=='' && $ad_endtime!==''){
			// echo "<script>alert('点击次数/到期时间，只能二选其一，空着即可');location.href='adlist.php'</script>";
			// exit;			
		// }
		// $row=$mysql->query("select * from `addata` where `ad_type`='{$ad_type}' and `ad_list`='{$ad_list}' limit 1");
		// if($row){
		// 	echo "<script>alert('广告已经存在请先删除');location.href='adlist.php'</script>";
		// 	exit;			
		// }
			$arr=array(
				//'id'=>null,
				'kad_title'=>$kad_title,
				'kad_logo'=>$kad_logo,
				'kad_url'=>$kad_url,
				'kad_profile'=>$kad_profile
			);
			$value=arr2s($arr);
			$mysql->query("insert into `kaddata` {$value}");
			echo "<script>alert('增加成功');location.href='kadlist.php'</script>";
			exit;
			
	}else{
			echo "<script>alert('请填写每一项');location.href='kadlist.php'</script>";
			exit;		
	}
}
?>
<?php include('head.php')?>   
	<link rel="stylesheet" href="../editor/themes/default/default.css" />
	<link rel="stylesheet" href="../editor/plugins/code/prettify.css" />
	<script charset="utf-8" src="../editor/kindeditor.js"></script>
	<script charset="utf-8" src="../editor/lang/zh_CN.js"></script>
	<script charset="utf-8" src="../editor/plugins/code/prettify.js"></script>
	<script>
		KindEditor.ready(function(K) {
			var editor1 = K.create('textarea[name="kad_content"]', {
				cssPath : '../editor/plugins/code/prettify.css',
				uploadJson : '../editor/php/upload_json.php',
				fileManagerJson : '../editor/php/file_manager_json.php',
				allowFileManager : true,
			});
			prettyPrint();
		});
	</script>
	<script>
		KindEditor.ready(function(K) {
			var uploadbutton = K.uploadbutton({
				button : K('#uploadButton')[0],
				fieldName : 'imgFile',
				url : '../editor/php/upload_json.php?dir=image',
				afterUpload : function(data) {
					if (data.error === 0) {
						var url = K.formatUrl(data.url, 'absolute');
						K('#img').val(url);
	                    $.post("../editor/php/dunling.php",{
	                    url:url
	                    },function(slta,sltb){
	                    //****//
	                    });
					} else {
						alert(data.message);
					}
				},
				afterError : function(str) {
					alert('自定义错误信息: ' + str);
				}
			});
			uploadbutton.fileBox.change(function(e) {
				uploadbutton.submit();
			});
		});
	</script> 
    <div class="container-fluid">
        
        <div class="row-fluid">
		<?php
		include('left.php');
		?>
<div class="span9">
            <h1 class="page-title">广告管理</h1>
			
<div class="well">
    <ul class="nav nav-tabs">
      <li class="active"><a href="#ad" data-toggle="tab">广告发布</a></li>
      <li><a href="#list" data-toggle="tab">广告管理</a></li>
    </ul>
    <div id="myTabContent" class="tab-content">
      <div class="tab-pane active in" id="ad">
	  <form action="kadlist.php" method="post">
	  <input type="hidden" name="do" value="ad">
		
		<label>标题：</label>
		<input type="text" value="" style="width:200px" name="kad_title">

		<label>LOGO上传：</label>
		<input style="width: 250px;" type="text" id="img" value="" name="kad_logo"/>
		<input type="button" id="uploadButton" class="ke-default-input" value="选择图片"/>

		<label>链接：</label>
		<input type="text" value="http://" style="width:200px" name="kad_url">

		<label>广告简介：</label>
		<input type="text" value="" style="width:200px" name="kad_profile">

		<hr>
		<button class="btn">提交</button>
	</form>	
      </div>
	  
	  
       <div class="tab-pane fade" id="list">
		<div class="well">
    <table class="table">
      <thead>
        <tr>
		  <th>广告标题</th>
		  <th>logo</th>
		  <th>链接</th>
		  <th>广告简介</th>
        </tr>
      </thead>
      <tbody>
<?php
$row_ad=$mysql->query("select * from `kaddata`");
foreach($row_ad as $v_ad){
print <<<table
        <tr>
          <td>{$v_ad['kad_title']}</td>
          <td>{$v_ad['kad_logo']}</td>
          <td>{$v_ad['kad_url']}</td>
          <td>{$v_ad['kad_profile']}</td>
		  <td>
			<a class="btn btn" href="edit_kad.php?id={$v_ad['id']}"><i class="icon-edit"></i></a>
			<a class="btn btn" href="?del_id={$v_ad['id']}"><i class="icon-trash"></i></a>
		  </td>
        </tr>
table;
}
	  ?>  
      </tbody>
    </table>
</div>
      </div>
  </div>

</div></div></div></div>
    
    <footer>
        <hr>
        
        <p class="pull-right"><!--power by right--></p>
        
        
        <p><!--power by --></p>
    </footer>
  

    

    <!-- Le javascript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
<script src="lib/bootstrap/js/bootstrap.js"></script>
<script type="text/javascript" src="../static/jquery.js"></script>
  </body>
</html>



